package com.tony.thread;

import com.tony.utils.TextUtil;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author Eliohn on 2018/8/8.
 * @version 1.0
 */
public class TaskPool {
    private int maxThreadNum = 110;

    public int threadNum;

    private String username;
    private String password;
    private int itemId;
    private String dPath;

    private long minId;
    private long maxId;

    private ThreadPoolExecutor pool = null;




    private void initPool() {


        pool = new ThreadPoolExecutor(maxThreadNum, maxThreadNum,
                9000L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>(1024));
    }

    public void taskRun(){

        initPool();

        //long minId=6221457754108733440l;
        //long maxId=6221913244258281472l;

        long size=(maxId-minId)/threadNum;

        for (int i =0;i < this.threadNum;i++){
            ExcuteThread excuteThread=new ExcuteThread();
            excuteThread.setThreadNum(i);
            excuteThread.setdPath(dPath);
            excuteThread.setUsername(this.username);
            excuteThread.setPassword(this.password);
            excuteThread.setItemId(this.itemId);
            excuteThread.setMinId(minId+i*size);
            excuteThread.setMaxId(minId+(i+1)*size);
            pool.execute(excuteThread);

            TextUtil.sleep(10);
        }

    }


    public long getMinId() {
        return minId;
    }

    public void setMinId(long minId) {
        this.minId = minId;
    }

    public long getMaxId() {
        return maxId;
    }

    public void setMaxId(long maxId) {
        this.maxId = maxId;
    }

    public int getThreadNum() {
        return threadNum;
    }

    public void setThreadNum(int threadNum) {
        this.threadNum = threadNum;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getItemId() {
        return itemId;
    }

    public void setItemId(int itemId) {
        this.itemId = itemId;
    }

    public String getdPath() {
        return dPath;
    }

    public void setdPath(String dPath) {
        this.dPath = dPath;
    }

    public ThreadPoolExecutor getPool() {
        return pool;
    }

    public void setPool(ThreadPoolExecutor pool) {
        this.pool = pool;
    }
}
